Constructor | |
---|---|
Text(master, **options) |
Options | |
---|---|
bg | |
cursor | |
font | |
fg | |
height - in lines | |
width - in characters | |
padx | |
pady | |
relief | |
selectbackground | |
state - NORMAL/DISABLED | |
wrap - WORD/CHAR |
Methods: | |
---|---|
insert(index ,string ) | inserts strings at the specified index location. |
delete(startindex [,endindex]) | deletes a specific character or a range of text. |
get(startindex [,endindex]) | returns a specific character or a range of text. |
from tkinter import * from tkinter.messagebox import * class MyFrame(Tk): def __init__(self): super().__init__() self.txt=Text(self,width=50,height=10,padx=10,pady=10) self.txt.pack(padx=10,pady=10) self.btn=Button(self,text="Show",command=self.showdata) self.btn.pack(fill=X,padx=10,pady=10) data="CCIT\nRajapeth\nAmravati" self.txt.insert("1.0",data) self.txt.insert("2.0","Gulshan Plaza\n") def showdata(self): data=self.txt.get("1.0",END) showinfo("DATA",data) frm=MyFrame() frm.mainloop()
from tkinter import * from tkinter.filedialog import * class MyFrame(Tk): def __init__(self): super().__init__() self.txt=Text(self,width=50,height=10,padx=10,pady=10) self.txt.pack(padx=10,pady=10) self.b1=Button(self,text="Open",bg="orange",command= self.openfile) self.b1.pack(fill=X,padx=10,pady=10) self.b2=Button(self,text="Save",bg="cyan") self.b2.pack(fill=X,padx=10,pady=10) def openfile(self): lst=[("Python",".py"),("Java",".java")] fnm=askopenfilename(filetypes=lst) if fnm!="": f=open(fnm) data=f.read() self.txt.insert("1.0",data) f.close() frm=MyFrame() frm.mainloop()